home *** CD-ROM | disk | FTP | other *** search
- Path: news.iag.net!news
- From: jatmon@iag.net (John R Buchan)
- Newsgroups: comp.lang.c
- Subject: Re: simple code, argc, argv, strcmp()
- Date: 3 Feb 1996 23:37:27 GMT
- Organization: Internet Access Group, Orlando, Florida
- Message-ID: <4f0rjn$sfh@news.iag.net>
- References: <11f7cc$17261a.3b3@daprez> <4etj7c$bma@news.iag.net> <fcusack-0202961621470001@mudskipper.cac.psu.edu>
- NNTP-Posting-Host: pm1-orl12.iag.net
- X-Newsreader: WinVN 0.99.7
-
- In article <fcusack-0202961621470001@mudskipper.cac.psu.edu>, fcusack@tdx.org
- says...
- >
- >In article <4etj7c$bma@news.iag.net>, jatmon@iag.net (John R Buchan) wrote:
- >
- >> In article <11f7cc$17261a.3b3@daprez>, otisg@panther.middlebury.edu says...
- >> >
- <snip>
- >> >int main (int argc, char **argv) {
- >> >
- >> > void Usage (void);
- >> > void Encode (int, char **);
- >> > void Decode (int, char **);
- >> >
- >> > if (!strcmp(argv[1],"-d") || !strcmp(argv[1],"-e")) {
- >> > Usage();
- >> > }
- >> <snip>
- >>
- >> I assume you mean this to call Usage if argv[1] is not "-e" and not "-d"?
- >> Change the || to &&.
- >
- >The && test would _never_ pass. argv[1] could never be both "-d" and "-e".
-
- You are correct, of course. Stupidity on my part. I tend to get careless
- about strcmp's reverse logic (ie returns False, when the strings match), when
- I am not paying attention (not an excuse, just an explanation). I normally
- compare the return value to 0, just to keep myself straight.
-
- >The || is correct here.
- <snip>
-
- ?? This would mean calling Usage for a correct first argument ("-e" or "-d"
- instead of an incorrect one. How about:
-
- if ( strcmp(argv[1],"-d") && strcmp(argv[1],"-e") )
-
- /* if contents of argv[1] is not "-d" and contents of argv[1] is not "-e" */
-
-
- I do apologize for the error. Thanks for pointing it out.
-
- --
- John R Buchan -:|:- Looking for that elusive FAQ? ftp to:
- jatmon@mail.iag.net -:|:- rtfm.mit.edu /pub/usenet-by-group/....
-
-